import { createStore } from 'vuex'

type User = {
  userId: string,
  account: string,
  name: string,
  scope: number,
  proof: string
}


const defaultState = {
  isLogin: false,
  user: {
    userId: '',
    account: '',
    name: '',
    scope: '',
    proof: ''
  },
  page: 1,// 上一页
}

export default createStore({
  state() {
    return defaultState
  },
  mutations: {
    login(state: typeof defaultState, payload) {
      state.user.userId = payload.id
      state.user.account = payload.account
      state.user.name = payload.name
      state.user.scope = payload.scope
      state.user.proof = payload.proof

      state.isLogin = true
    },
    logout(state: typeof defaultState) {
      let key: keyof User
      for (key in state.user) {
        state.user[key] = ''
      }
      state.isLogin = false
    },
    savePage(state: typeof defaultState, payload) {
      state.page = payload
    }
  },
  actions: {
  },
  modules: {
  }
})
